﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using ThoiTrang.Business;
using ThoiTrang.Entities;


public partial class Admin_adm_stats_articles : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            for (DateTime dt = Convert.ToDateTime("01/01/2006"); dt <= DateTime.Now.AddYears(3); dt = dt.AddYears(1))
            {
                ddlPeriodYear.Items.Add(new ListItem(dt.Year.ToString(), dt.Year.ToString()));
                ddlFromYear.Items.Add(new ListItem(dt.Year.ToString(), dt.Year.ToString()));
            }

            ddlFromYear.Items.Insert(0, new ListItem("", ""));
            ddlFromYear.SelectedIndex = 1;
            ddlPeriodYear.SelectedValue = DateTime.Now.Year.ToString();
           ddlFromMonth.SelectedIndex = 2;

            loadData();
        }
    }

    public void loadData()
    {
        string dateTo = "";
        string dateFrom = "";
        int page = Convert.ToInt32(Request.QueryString["p"] == null ? "1" : Request.QueryString["p"]);

        string doctype = Request.QueryString["DocType"] == null ? "3" : Request.QueryString["DocType"];

        dateTo = ddlPeriodYear.SelectedValue + "-" + ddlPeriodMonth.SelectedValue + "-01";// +"-01 23:59:59";
        if (ddlFromMonth.SelectedValue != "" && ddlFromYear.SelectedValue != "")
        {
            dateFrom = ddlFromYear.SelectedValue + "-" + ddlFromMonth.SelectedValue + "-01";// +"-28 00:00:00";
        }

        DataSet ds = a_ArticleService.a_StatReport_Articles(dateTo, dateFrom,
               ddlSortBy.SelectedValue, ddlOrderBy.SelectedValue,
               txtSelectTop.Text, doctype, page, 20, 6);

        if (ds.Tables.Count < 2)
        {
            ltrCurrentPage.Text = "No item found";
        }
        else
        {
            DataTable dtbPaging = ds.Tables[0];

            DataList1.DataSource = ds.Tables[1];
            DataList1.DataBind();

            //  GridView1.DataSource = ds.Tables[1];
            //  GridView1.DataBind();
            ltrPaging.Text = CommonFunc.QueryPaging(page, Convert.ToInt32(dtbPaging.Rows[0]["TotalRecords"]) / 20 + 1, 6);
            ltrPagingBot.Text = ltrPaging.Text;
            ltrPaging.Visible = false;
            ltrPagingBot.Visible = false;
            AdminPaging1.Total = Convert.ToInt32(dtbPaging.Rows[0]["TotalRecords"]);
            AdminPaging2.Total = Convert.ToInt32(dtbPaging.Rows[0]["TotalRecords"]);
        }

    }

    public string DetailImage(object aID, object kTitle, object fYear, object imgNo)
    {
        string res = "";
        res = kTitle.ToString().ToLower().Trim().Replace(" ", "-");
        res = FOConstants.Dir_ImgArticle + res + "-" + fYear.ToString() + "-l" + aID.ToString() + ".jpg";
        return res;
    }
    protected void btnGo_Click(object sender, EventArgs e)
    {
        loadData();
    }

    public string getCKID()
    {
        return SessionManager.GetCookie();
    }
}
